Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request color presentations when clicking on a color box #2065

Merged
merged 8 commits into from
Sep 25, 2022

Conversation

jwortmann
Copy link
Member

This runs the textDocument/colorPresentation request when clicking on a color box, and shows the results in a quick panel. I think it is better to apply the change into the file only after selecting one of the quick panel entries, rather than immediately like it's implemented in the VSCode color picker when cycling through the different color formats. Because the conversion from RGB to HSL/HWB and back again might alter the original color (e.g. #dddddd -> hsl(0, 0%, 87%) -> hwb(0 87% 13%) -> rgb(222, 222, 222) -> #dedede).

There is no special server capability for this request by the way, so we can't decide beforehand whether or not it is supported by the server and is useful to make the color box clickable. (But maybe it's expected that servers that have the colorProvider capability, which is used for textDocument/documentColor, should also support colorPresentation.)

And there can be optional "additionalTextEdits" in the response, which are ignored in this PR. I don't really know what should be the use of those; maybe it's to replace all occurencies of the particular color. But that seems rather dangerous or unexpected for the user to me, so I guess it's better to leave this out for now.

Note that you can observe two color boxes for a very short amount of time after selecting a quick panel entry, but this seems unrelated to this pull request. It's probably some kind of bug in the code how the color box phantoms are updated, or in the lsp_apply_document_edit command (or in how these two situations work together).

And in case a minihtml color picker gets implemented at a later point, this functionality could be adjusted with minimal changes to be invoked from a link in the color picker.

plugin/color.py Show resolved Hide resolved
plugin/session_buffer.py Outdated Show resolved Hide resolved
@predragnikolic
Copy link
Member

on Linux there is an underline
image

this should fix that

COLOR_BOX_HTML = """
<style>
        display: inline-block;
        // ....
        background-color: {color};
+        text-decoration: none;
    }}

Copy link
Member

@predragnikolic predragnikolic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from #2065 (comment)

Everything else looks good.

@rwols rwols merged commit ae64f10 into sublimelsp:main Sep 25, 2022
@jwortmann jwortmann deleted the color-presentation branch September 25, 2022 19:32
rchl added a commit that referenced this pull request Sep 27, 2022
* main:
  Fix issues with diagnostics panel toggling on save (#2063)
  Request color presentations when clicking on a color box (#2065)
  Import new imports like NotRequired from "typing"
  Ensure "Source Actions..." request includes the "source" kind (#2064)
  refactor(types): Mark properties with NotRequired (#2062)
  Add template variable `$text_document_position` in execute command (#2061)
  Only update content of diagnostics panel when visible (#2054)
  Remove Range class and rename RangeLsp to Range (#2058)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants